/**
 * Copyright 2016 vip.com.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 * </p>
 **/

package spring.cloud.tasks.api.service.impl.statistics.analyzer;

import spring.cloud.tasks.api.domain.*;
import spring.cloud.tasks.api.zookeeper.ZooKeeper;

import java.util.List;

/**
 * @author timmy.hu
 */
public class StatisticsModel {

    private ExecutorInfoAnalyzer executorInfoAnalyzer;

    private OutdatedNoRunningJobAnalyzer outdatedNoRunningJobAnalyzer;

    private UnableFailoverJobAnalyzer unableFailoverJobAnalyzer;

    private Timeout4AlarmJobAnalyzer timeout4AlarmJobAnalyzer;


    private JobStatisticsAnalyzer jobStatisticsAnalyzer;

    private DomainStatisticsAnalyzer domainStatisticsAnalyzer;

    private ZkClusterDailyCountAnalyzer zkClusterDailyCountAnalyzer;

    public void analyzeExecutor(ZooKeeper zooKeeper, NameSpaceConfiguration nameSpaceConfiguration)
            throws Exception {
        executorInfoAnalyzer.analyzeExecutor(zooKeeper, nameSpaceConfiguration);
    }

    public JobStatistics analyzeJobStatistics(ZooKeeper zooKeeper, String job,
                                              NameSpaceConfiguration config) throws Exception {
        return jobStatisticsAnalyzer.analyze(zooKeeper, job, config, executorInfoAnalyzer);
    }

    public void analyzeShardingCount(ZooKeeper zooKeeper, DomainStatistics domainStatistics) {
        domainStatisticsAnalyzer.analyzeShardingCount(zooKeeper, domainStatistics);
    }

    public void analyzeOutdatedNoRunningJob(ZooKeeper zooKeeper, List<AbnormalJob> oldAbnormalJobs,
                                            String jobName, String jobDegree, NameSpaceConfiguration config) {
        outdatedNoRunningJobAnalyzer.analyze(zooKeeper, oldAbnormalJobs, jobName, jobDegree, config);
    }

    public void analyzeTimeout4AlarmJob(ZooKeeper zooKeeper,
                                        List<Timeout4AlarmJob> oldTimeout4AlarmJob, String jobName, String jobDegree,
                                        NameSpaceConfiguration config) {
        timeout4AlarmJobAnalyzer.analyze(zooKeeper, oldTimeout4AlarmJob, jobName, jobDegree, config);
    }

    public void analyzeUnableFailoverJob(ZooKeeper zooKeeper, String jobName, String jobDegree,
                                         NameSpaceConfiguration config) {
        unableFailoverJobAnalyzer.analyze(zooKeeper, jobName, jobDegree, config);
    }


    public void analyzeProcessCount(DomainStatistics domainStatistics, List<String> jobs,
                                    NameSpaceConfiguration config) {
        domainStatisticsAnalyzer.analyzeProcessCount(domainStatistics, zkClusterDailyCountAnalyzer, jobs,
                jobStatisticsAnalyzer.getJobMap(), config);
    }

    public ExecutorInfoAnalyzer getExecutorInfoAnalyzer() {
        return executorInfoAnalyzer;
    }

    public void setExecutorInfoAnalyzer(ExecutorInfoAnalyzer executorInfoAnalyzer) {
        this.executorInfoAnalyzer = executorInfoAnalyzer;
    }

    public OutdatedNoRunningJobAnalyzer getOutdatedNoRunningJobAnalyzer() {
        return outdatedNoRunningJobAnalyzer;
    }

    public void setOutdatedNoRunningJobAnalyzer(OutdatedNoRunningJobAnalyzer outdatedNoRunningJobAnalyzer) {
        this.outdatedNoRunningJobAnalyzer = outdatedNoRunningJobAnalyzer;
    }

    public UnableFailoverJobAnalyzer getUnableFailoverJobAnalyzer() {
        return unableFailoverJobAnalyzer;
    }

    public void setUnableFailoverJobAnalyzer(UnableFailoverJobAnalyzer unableFailoverJobAnalyzer) {
        this.unableFailoverJobAnalyzer = unableFailoverJobAnalyzer;
    }

    public Timeout4AlarmJobAnalyzer getTimeout4AlarmJobAnalyzer() {
        return timeout4AlarmJobAnalyzer;
    }

    public void setTimeout4AlarmJobAnalyzer(Timeout4AlarmJobAnalyzer timeout4AlarmJobAnalyzer) {
        this.timeout4AlarmJobAnalyzer = timeout4AlarmJobAnalyzer;
    }


    public JobStatisticsAnalyzer getJobStatisticsAnalyzer() {
        return jobStatisticsAnalyzer;
    }

    public void setJobStatisticsAnalyzer(JobStatisticsAnalyzer jobStatisticsAnalyzer) {
        this.jobStatisticsAnalyzer = jobStatisticsAnalyzer;
    }

    public DomainStatisticsAnalyzer getDomainStatisticsAnalyzer() {
        return domainStatisticsAnalyzer;
    }

    public void setDomainStatisticsAnalyzer(DomainStatisticsAnalyzer domainStatisticsAnalyzer) {
        this.domainStatisticsAnalyzer = domainStatisticsAnalyzer;
    }

    public ZkClusterDailyCountAnalyzer getZkClusterDailyCountAnalyzer() {
        return zkClusterDailyCountAnalyzer;
    }

    public void setZkClusterDailyCountAnalyzer(ZkClusterDailyCountAnalyzer zkClusterDailyCountAnalyzer) {
        this.zkClusterDailyCountAnalyzer = zkClusterDailyCountAnalyzer;
    }
}
